import os
import bpy


class memoryColorPanel(bpy.types.Panel):
    bl_idname = 'memory.ColorInfo'
    bl_label = 'Color Info'
    bl_space_type = 'NODE_EDITOR'
    bl_region_type = 'TOOLS'
    bl_category = 'Memory'

    def draw(self, context):
        purple_ball = icon_collections["purple_ball"]["purple_ball"]
        gray_ball = icon_collections["gray_ball"]["gray_ball"]
        green_ball = icon_collections["green_ball"]["green_ball"]
        yellow_ball = icon_collections["yellow_ball"]["yellow_ball"]
        blue_ball = icon_collections["blue_ball"]["blue_ball"]
        red_ball = icon_collections["red_ball"]["red_ball"]
        white_ball = icon_collections["white_ball"]["white_ball"]

        col = self.layout.column(align=True)
        col.label(text=": Heaps", icon_value=purple_ball.icon_id)
        col.label(text=": DLLs", icon_value=gray_ball.icon_id)
        col.label(text=": Stacks", icon_value=green_ball.icon_id)
        col.label(text=": Mapped Files", icon_value=yellow_ball.icon_id)
        col.label(text=": root node", icon_value=blue_ball.icon_id)
        col.label(text=": new or changed nodes", icon_value=red_ball.icon_id)
        col.label(text=": normal VAD nodes", icon_value=white_ball.icon_id)

# icon collection
icon_collections = {}


def register():
    import bpy.utils.previews
    icon = bpy.utils.previews.new()
    icons_dir = "../../../icons"
    for ball in os.listdir(icons_dir):
        icon.load(ball[:-4], os.path.join(icons_dir, ball), 'IMAGE')
        icon_collections[ball[:-4]] = icon
    bpy.utils.register_class(memoryColorPanel)

def unregister():
    for icon in icon_collections.values():
        bpy.utils.previews.remove(icon)
    icon_collections.clear()
    bpy.utils.unregister_class(memoryColorPanel)

if __name__ == "__main__":
    register()